<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.xjtu.shopcar.domin.*" %>
<%@ page import="com.xjtu.shopcar.db.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>



 <table border="1" align="center" width="80%">
       <caption>图书信息</caption>
        <tr>
           <th>编号</th>
           <th>书名</th>
           <th>作者</th>
           <th>单价</th>
           <td>操作</td>
         </tr>
     <c:forEach  var="book"  items="${bookList}">
         <tr>
           <td>${book.value.id}</td>
           <td>${book.value.name}</td>
           <td>${book.value.author}</td>
           <td>${book.value.price}</td>
           <td><a href="/myday10/BuyServlet?id=${book.value.id}" style="text-decoration: none;">购买</a></td>
         
         </tr>
   
   
     </c:forEach>
   </table>
 
 
 <hr/>
 
<table border="1" width="40%" align="center">
  <caption>最近购买记录为:</caption>
 <% 
   Cookie[] cookies  = request.getCookies();
    for(int i=0;cookies!=null && i<cookies.length;i++){
	if("historyBookId".equals(cookies[i].getName())){
		String value = cookies[i].getValue();//1-2-3
		//拆分
		String[] ids  = value.split("-");	
		request.setAttribute("name", ids);
	    for(String id:ids){%>
			  <tr align="center">
			<%Book book = BookList.findBookById(id);	
		     String name = 	book.getName();
			// System.out.print(name);
			 request.setAttribute("name", name);
			%>	
              <td>${name }</td>
			</tr>
	<% 		
		}			
	}
  }
  %>
  
  
  
 </table>

 
</body>
</html>